
/*******************************************************************************
* Copyright (C) JuCheap
* 
* Author: JuCheap
* Create Date: 10/18/2019 11:54:03
* Description: AutoMapper映射关系配置文件(手动添加的对象映射配置，在此文件里面修改) 
* 
* Revision History:
* Date         Author               Description
*
*********************************************************************************/

using AutoMapper;
using JuCheap.Core.Data.Entity;
using JuCheap.Core.Model;
using JuCheap.Core.Infrastructure.Utilities;
using Microsoft.Extensions.DependencyInjection;
using JuCheap.Core.Model.Message;

namespace JuCheap.Core.Service
{
    /// <summary>
    /// AutoMapp自定义对象映射关系配置文件
    /// </summary>
    public class AutoMapperProfileExtention : AutoMapperProfile
    {
        /// <summary>
        /// 自定义对象映射关系配置
        /// </summary>
        public AutoMapperProfileExtention() : base()
        {
            CreateMap<SysUser, CurrentUserDto>();
            CreateMap<UserProfileUpdateDto, SysUser>();
            CreateMap<CompanyCreateRequestDto, SysCompany>();
            CreateMap<CompanyEditRequestDto, SysCompany>();
            CreateMap<UserCreateRequestDto, SysUser>();
            CreateMap<UserEditRequestDto, SysUser>()
                .ForMember(x => x.Password, e => e.Ignore())
                .ForMember(x => x.SecurityKey, e => e.Ignore());
            CreateMap<RoleCreateRequestDto, SysRole>();
            CreateMap<RoleEditRequestDto, SysRole>();
            CreateMap<MenuCreateRequestDto, SysMenu>();
            CreateMap<MenuEditRequestDto, SysMenu>();
            CreateMap<DepartmentCreateRequestDto, SysDepartmentDto>();
            CreateMap<DepartmentEditRequestDto, SysDepartmentDto>();
            CreateMap<UpgradeLogAddDto, SysUpgradeLogDto>();
            CreateMap<MessageCreateRequestDto, SysMessage>();

            CreateMap<CategoryCreateRequestDto, ProductCategoryDto>();
            CreateMap<CategoryEditRequestDto, ProductCategoryDto>();

            CreateMap<ProductCreateRequestDto, Product>();
            CreateMap<ProductEditRequestDto, Product>();
        }
    }

    /// <summary>
    /// AutoMapper配置扩展
    /// </summary>
    public static class JuCheapAutoMapperExtention
    {
        /// <summary>
        /// 加载AutoMapper的映射配置关系
        /// </summary>
        /// <param name="services"></param>
        public static void UseAutoMapperExtention(this IServiceCollection services)
        {
            services.AddAutoMapper(config =>
            {
                config.AddProfile<AutoMapperProfileExtention>();
            }, typeof(AutoMapperProfileExtention).Assembly);
        }
    }
}

